package edu.siu.math.egut.drivers;

import java.util.ArrayList;
import java.util.List;


import edu.siu.math.egut.util.ExceptionalGroup;
import edu.siu.math.egut.util.ExceptionalGroupElement;
import edu.siu.math.egut.util.NotARootException;
import edu.siu.math.egut.util.LaurentPolynomial;
import edu.siu.math.egut.util.WeylElement;

/**
 * Jiang-Rallis.
 * 
 * @author joe pleso
 *
 */
public class JiangRallis {

    
    
    
    /**
     * Jiang-Rallis.
     * 
     * @param args ignored
     * @throws NotARootException thrown if pigs are flying
     */
    public static void main(String[] args) throws NotARootException {
	
	ExceptionalGroup g = ExceptionalGroup.getGroup(2);
	
	int [][] roots = g.getRoots();

	WeylElement wAlpha = new WeylElement(g,0);
	WeylElement wBeta = new WeylElement(g,1);
	WeylElement product = (WeylElement) wAlpha.copy();
	
	product = product.times(wBeta);
	product = product.times(product);
	product = product.times(wAlpha);//wABABA
	
	//System.out.println(product);
	LaurentPolynomial v = LaurentPolynomial.create("v");
	ExceptionalGroupElement n = g.chi(
		roots[4], LaurentPolynomial.create("x").opposite());
	n = ExceptionalGroupElement.times(
		n, g.chi(roots[3], LaurentPolynomial.create("y")));
	n = ExceptionalGroupElement.times(
		n,g.chi(roots[5], LaurentPolynomial.create("z").opposite()));
	n = ExceptionalGroupElement.times(
		n,g.chi(roots[2], LaurentPolynomial.create("u").opposite()));
	n = ExceptionalGroupElement.times(
		n,g.chi(roots[1], v));
	n = ExceptionalGroupElement.times(
		product,n);
	//wABABA n(x,y,z,u,v)
	
	
	
	
	
	System.out.println(n);
	n.remove(n.getNumberOfTerms()-1);
	ExceptionalGroupElement x13 = g.chi(g.getPositiveRoots()[4], v.opposite());
        n= ExceptionalGroupElement.times(n,x13);
	//Scanner scanner = new Scanner(System.in);
        List<Integer> allowed = new ArrayList <Integer>();
        n.pushLeft(4);
        do
	{
            allowed.clear();
            allowed.add(7);
            allowed.add(8);
            allowed.add(9);
            allowed.add(11);
	    
	    for (int i = 0; i < n.getNumberOfTerms(); i++){
		Integer curRoot = g.findIndex(n.getRoot(i));
		if (!allowed.remove(curRoot) ){
		    if (i == 0)
			n.remove(i);
		    else
			n.pushLeft(i);
		    break;
		}
	    }
	    
            
            
	   
	  //  n.pushLeft(scanner.nextInt());
	}while(!allowed.isEmpty());
        System.out.println(n);
	
	
		
    }

}
